import 'dart:convert';

class JsonUtil{

  /// 将数组编码为字符串
  static String encodeJson(dynamic obj) => jsonEncode(obj);

  /// 将 JSON 字符串解析为 List<String>
  static List<String> decodeStringList(dynamic source) {
    if (source == null || source.toString().isEmpty) return [];
    try {
      return List<String>.from(jsonDecode(source));
    } catch (_) {
      return [];
    }
  }

  /// 将 JSON 字符串解析为 List<int>
  static List<int> decodeIntList(dynamic source) {
    if (source == null || source.toString().isEmpty) return [];
    try {
      return List<int>.from(jsonDecode(source));
    } catch (_) {
      return [];
    }
  }
}